/*
	Create variables for the analysis dataset
*/

use "$data/2_processed/panel_appended.dta", clear

drop if consent == 0

********************************************************************************
*  BIG 5 PERSONALITY TRAITS
********************************************************************************

// Generate averages for specific Big 5 traits (not overall average)
egen big5_avg_extra = rowmean(big5_extrovert big5_shy)
egen big5_avg_agreea = rowmean(big5_critic big5_sympathetic)
egen big5_avg_consc = rowmean(big5_reliable big5_disorganized)
egen big5_avg_emoti = rowmean(big5_anxious big5_calm)
egen big5_avg_open = rowmean(big5_open big5_conventional)

********************************************************************************
*  CONSCIENTIOUSNESS TRAITS
********************************************************************************

egen trait_avg_orga = rowmean(trait_tidy trait_follow_schedule trait_followup_method ///
    trait_organize_schedule trait_clean_up trait_orga_pers_spaces ///
    trait_keep_organized trait_keep_tidy)

egen trait_avg_indus = rowmean(trait_make_plan trait_work_goals trait_set_clear_goals ///
    trait_set_high_standards trait_change_setback trait_work_hard ///
    trait_focus_goals trait_make_plan_for_goal trait_keep_trying_if_fail)
    
egen trait_avg_resp = rowmean(trait_attentive_others trait_others_dependent trait_keep_promises ///
    trait_fulfill_promises trait_up_to_responsib trait_respect_engagements ///
    trait_others_count trait_fulfill_duty trait_manage_responsib)

egen trait_avg_punc = rowmean(trait_remorse_late trait_earlier_meet trait_avoid_late ///
    trait_avoid_procrast trait_on_time trait_late_meetings)

********************************************************************************
*  CONTROL VARIABLES
********************************************************************************

// Age calculation
gen age = 2019 - yob if survey_round == 1
replace age = 2019 - yob if survey_round == 2
replace age = 2020 - yob if survey_round == 3

// Education indicator
gen educ_high = (educ > 4 & educ < .)
label values educ_high yesno

********************************************************************************
*  EARNINGS CONSTRUCTION
********************************************************************************

sort	id survey_round

* -------- Building change amounts from range (3 tiers) -------- *

local	tiers "low mid top"

local	low_base 		"4"
local	low_chg 		"0"
local	low_chg_range 	"0"

local	mid_base 		"2"
local	mid_chg 		"2500"
local	mid_chg_range	"25000"

local	top_base		"1"
local	top_chg 		"5000"
local	top_chg_range	"50000"


foreach tier in `tiers' {
    gen		earn_amount_change_`tier' = 0

    replace	earn_amount_change_`tier' = 5000/``tier'_base' ///
        if earn_amount_change_aug19 == 1 | earn_amount_change_jan20 == 1
        
    replace	earn_amount_change_`tier' = 5000+``tier'_chg' ///
        if earn_amount_change_aug19 == 2 | earn_amount_change_jan20 == 2
        
    replace	earn_amount_change_`tier' = 10000+``tier'_chg' ///
        if earn_amount_change_aug19 == 3 | earn_amount_change_jan20 == 3
        
    replace	earn_amount_change_`tier' = 15000+``tier'_chg' ///
        if earn_amount_change_aug19 == 4 | earn_amount_change_jan20 == 4
        
    replace	earn_amount_change_`tier' = 20000+``tier'_chg' ///
        if earn_amount_change_aug19 == 5 | earn_amount_change_jan20 == 5
        
    replace	earn_amount_change_`tier' = 25000+``tier'_chg' ///
        if earn_amount_change_aug19 == 6 | earn_amount_change_jan20 == 6
        
    replace	earn_amount_change_`tier' = 30000+``tier'_chg' ///
        if earn_amount_change_aug19 == 7 | earn_amount_change_jan20 == 7
        
    replace	earn_amount_change_`tier' = 35000+``tier'_chg' ///
        if earn_amount_change_aug19 == 8 | earn_amount_change_jan20 == 8
        
    replace	earn_amount_change_`tier' = 40000+``tier'_chg' ///
        if earn_amount_change_aug19 == 9 | earn_amount_change_jan20 == 9
}

* Building monthly income ranges

foreach tier in `tiers' {
    gen		earn_range_`tier' = 0
    replace	earn_range_`tier' = 80000/``tier'_base' 		if earn_avg_month_range==1
    replace	earn_range_`tier' = 80000+``tier'_chg_range' 	if earn_avg_month_range==2
    replace	earn_range_`tier' = 130000+``tier'_chg_range' 	if earn_avg_month_range==3
    replace	earn_range_`tier' = 180000+``tier'_chg_range' 	if earn_avg_month_range==4
    replace	earn_range_`tier' = 230000+``tier'_chg_range' 	if earn_avg_month_range==5
    replace	earn_range_`tier' = 280000+``tier'_chg_range' 	if earn_avg_month_range==6
}

* Generate ranges for other jobs — mid-range only

gen		last7d_oj_earn_range_amount = .
replace	last7d_oj_earn_range_amount = 40000 if last7d_oj_earn_range == 1
replace	last7d_oj_earn_range_amount = 105000 if last7d_oj_earn_range == 2
replace	last7d_oj_earn_range_amount = 155000 if last7d_oj_earn_range == 3
replace	last7d_oj_earn_range_amount = 205000 if last7d_oj_earn_range == 4
replace	last7d_oj_earn_range_amount = 255000 if last7d_oj_earn_range == 5
replace	last7d_oj_earn_range_amount = 320000 if last7d_oj_earn_range == 6

* -------- Generating interpolated earnings -------- *

* Transform those missings to 0 so that multiplications below return a value
replace	earn_change_aug19 = 0 if earn_change_aug19 == . & survey_round != 1
replace	earn_change_jan20 = 0 if earn_change_jan20 == . & survey_round != 1

replace earn_dir_change_aug19 = 0 if earn_dir_change_aug19 ==. | earn_dir_change_aug19 < -1
replace earn_dir_change_jan20 = 0 if earn_dir_change_jan20 ==. | earn_dir_change_jan20 < -1

// Taking the previous round's wage, multiplying by whether it changed
// (0 No, 1 Yes), multiplying by the direction of change (-1 decrease
// 1 increase) and by the different tiers of amount change (top, mid and low)
// _top decreases are the **largest** decreases!

* Average earnings for last month ------

foreach tier in `tiers' {
    gen		inter_earnavgmonth_`tier' = earn_avg_month if earn_avg_month != .

    * Use range to fill missing average wages
    replace inter_earnavgmonth_`tier' = earn_range_`tier' if earn_avg_month == .

    * Use last 7 days earnings to fill missing average wage
    replace inter_earnavgmonth_`tier' = last7d_earn_avg * 4 ///
            if survey_round == 3 & eif_still_work == 0 & earn_avg_month == .

    * Interpolation for round 2
    by id:	replace inter_earnavgmonth_`tier' = inter_earnavgmonth_`tier'[1] + ///
            earn_change_aug19*(earn_dir_change_aug19*earn_amount_change_`tier') ///
            if survey_round == 2 & earn_avg_month == .

    * If the earn_change_jan20 == 0, then we just get the previous round's wage (either round 1 or 2 wage)
    * If the earn_change_jan20 != 0 and round 2 is missing, then we assume that round 2 earnings == round 1 
    * and apply earn_amount_change on round 1 earnings

    by id:	replace	inter_earnavgmonth_`tier' = inter_earnavgmonth_`tier'[_n-1] + ///
            earn_change_jan20*(earn_dir_change_jan20*earn_amount_change_`tier') ///
            if survey_round == 3 & earn_avg_month == .
            
    // Adding other jobs earnings: measured for last 7 days, extrapolated to month

    * If we have a "direct" amount, use it
    replace	inter_earnavgmonth_`tier' = inter_earnavgmonth_`tier' + (last7d_oj_earn * 4) ///
    if last7d_oj_earn != .

    * If we only have a range, use the middle of the range as amount
    replace	inter_earnavgmonth_`tier' = inter_earnavgmonth_`tier' + (last7d_oj_earn_range_amount * 4) ///
    if last7d_oj_earn_range != . & last7d_oj_earn == .

    * Earnings are 0 if unemployed
    replace	inter_earnavgmonth_`tier' = 0 if survey_round == 3 & (last7d_status == 3 | last7d_status==6)

    * Clean for negative earnings
    replace	inter_earnavgmonth_`tier' = 0 if inter_earnavgmonth_`tier' < 0
}

* Last earnings ------

foreach tier in `tiers' {
    gen inter_earnlstmonth_`tier' = earn_last_month if earn_last_month != .
    
    replace inter_earnlstmonth_`tier' = earn_range_`tier' if earn_last_month == .
    
    replace inter_earnlstmonth_`tier' = last7d_earn_avg * 4 ///
        if survey_round == 3 & eif_still_work == 0 & earn_last_month == .
                
    by id: replace inter_earnlstmonth_`tier' = inter_earnlstmonth_`tier'[1] + ///
        earn_change_aug19*(earn_dir_change_aug19*earn_amount_change_`tier') ///
        if survey_round == 2 & earn_last_month == .
    
    by id: replace inter_earnlstmonth_`tier' = inter_earnlstmonth_`tier'[_n-1] + ///
        earn_change_jan20*(earn_dir_change_jan20*earn_amount_change_`tier') ///
        if survey_round == 3 & earn_last_month == .
    
    replace inter_earnlstmonth_`tier' = inter_earnlstmonth_`tier' + (last7d_oj_earn * 4) ///
        if last7d_oj_earn != .
    
    replace inter_earnlstmonth_`tier' = inter_earnlstmonth_`tier' + (last7d_oj_earn_range_amount * 4) ///
        if last7d_oj_earn_range != . & last7d_oj_earn == .
        
    replace inter_earnlstmonth_`tier' = 0 if survey_round == 3 & (last7d_status == 3 | last7d_status==6)
    
    replace inter_earnlstmonth_`tier' = 0 if inter_earnlstmonth_`tier' < 0
}

// Clean up temporary variables
drop earn_amount_change_mid earn_range_mid last7d_oj_earn_range_amount earn_amount_change_low earn_amount_change_top earn_range_low earn_range_top

// Compute hourly wage
gen month_hours_worked = last7d_hours_worked*4.33
gen hourly_wage = inter_earnlstmonth_mid/month_hours_worked

********************************************************************************
*  HOUSEHOLD FINANCE VARIABLES (MID-TIER ONLY)
********************************************************************************

// Use original local macro structure for mid-tier estimates
local mid_base "2"
local mid_chg "(1/2)"

// Household income (mid-tier estimates only)
gen hhincome_mid = .

// Round 1 & 2 income ranges
replace hhincome_mid = 80000/`mid_base' if hh_revenue_range_r1r2 == 1
replace hhincome_mid = 80000+((130000-80000)*`mid_chg') if hh_revenue_range_r1r2 == 2
replace hhincome_mid = 130000+((180000-130000)*`mid_chg') if hh_revenue_range_r1r2 == 3
replace hhincome_mid = 180000+((230000-180000)*`mid_chg') if hh_revenue_range_r1r2 == 4
replace hhincome_mid = 230000+((280000-230000)*`mid_chg') if hh_revenue_range_r1r2 == 5
replace hhincome_mid = 330000+((280000-230000)*`mid_chg') if hh_revenue_range_r1r2 == 6

// Round 3 income ranges
replace hhincome_mid = 8000/`mid_base' if hh_revenue_range_r3 == 1
replace hhincome_mid = 8000+((20000-8000)*`mid_chg') if hh_revenue_range_r3 == 2
replace hhincome_mid = 20000+((40000-20000)*`mid_chg') if hh_revenue_range_r3 == 3
replace hhincome_mid = 40000+((60000-40000)*`mid_chg') if hh_revenue_range_r3 == 4
replace hhincome_mid = 60000+((80000-60000)*`mid_chg') if hh_revenue_range_r3 == 5
replace hhincome_mid = 80000+((130000-80000)*`mid_chg') if hh_revenue_range_r3 == 6
replace hhincome_mid = 130000+((180000-130000)*`mid_chg') if hh_revenue_range_r3 == 7
replace hhincome_mid = 180000+((230000-180000)*`mid_chg') if hh_revenue_range_r3 == 8
replace hhincome_mid = 230000+((280000-230000)*`mid_chg') if hh_revenue_range_r3 == 9
replace hhincome_mid = 330000+((280000-230000)*`mid_chg') if hh_revenue_range_r3 == 10

// Savings and debt (mid-tier estimates only)
local varz "formal_save informal_save formal_debt informal_debt"
local formal_save_v "hh_formal_savings"
local informal_save_v "hh_informal_savings"
local formal_debt_v "hh_formal_debt"
local informal_debt_v "hh_informal_debt"

foreach v in `varz' {
    gen `v'_mid = .
    replace `v'_mid = 0 if ``v'_v' == 0
    replace `v'_mid = 50000/`mid_base' if ``v'_v' == 1
    replace `v'_mid = 50000+(50000*`mid_chg') if ``v'_v' == 2
    replace `v'_mid = 100000+(50000*`mid_chg') if ``v'_v' == 3
    replace `v'_mid = 150000+(50000*`mid_chg') if ``v'_v' == 4
    replace `v'_mid = 200000+(50000*`mid_chg') if ``v'_v' == 5
    replace `v'_mid = 250000+(50000*`mid_chg') if ``v'_v' == 6
}

// Total debt and savings
gen total_save_mid = formal_save_mid + informal_save_mid
gen total_debt_mid = formal_debt_mid + informal_debt_mid

// Clean up intermediate variables
drop formal_save_mid informal_save_mid formal_debt_mid informal_debt_mid

********************************************************************************
*  BACKGROUND CHARACTERISTICS
********************************************************************************

// First formal job indicator
gen first_formal1 = 1 if bef_eif_job == 0
replace first_formal1 = 0 if bef_eif_job == 1
by id: egen first_formal = max(first_formal1)
drop first_formal1
label values first_formal yesno

// Recent migrant indicator
gen recent_migr1 = 1 if resid_since < 5 & resid_prev_regi != 1
replace recent_migr1 = 0 if (resid_since > 5 | resid_prev_regi == 1) & (resid_since != .)
by id: egen recent_migr = max(recent_migr1)
drop recent_migr1
label values recent_migr yesno

********************************************************************************
*  COVID-19 VARIABLES
********************************************************************************

// COVID-19 protection measures
egen covid_meas_count = rowtotal(covid_protect_m1 covid_protect_m2 covid_protect_m3 ///
                                covid_protect_m4 covid_protect_m5 covid_protect_m6 ///
                                covid_protect_m7 covid_protect_m8)

egen covid_effect_meas_count = rowtotal(covid_protect_m1 covid_protect_m2 covid_protect_m3 ///
    covid_protect_m4 covid_protect_m5 covid_protect_m6)

// COVID-19 symptoms and work changes
egen covid_any_sympt = rowmax(covid_sympt_*)

egen covid_change_work_any = rowmax(covid_change_work_cond1 covid_change_work_cond2 ///
                                   covid_change_work_cond3 covid_change_work_cond4 ///
                                   covid_change_work_cond5)

label values covid_any_sympt covid_change_work_any yesno

// COVID-19 financial impacts
gen covid_feb_revenue_lower = (covid_feb_revenue == 3) if survey_round == 3

gen covid_feb_tot_revenue_lower = (covid_feb_tot_revenue == 3) if survey_round == 3

gen covid_feb_remittances_lower = (covid_feb_remittances == 3) if survey_round == 3

gen covid_feb_food_exp_higher = (covid_feb_food_expenditures == 1) if survey_round == 3

gen covid_feb_health_exp_higher = (covid_feb_health_expenditures == 1) if survey_round == 3

gen covid_feb_edu_exp_higher = (covid_feb_edu_expenditures == 1) if survey_round == 3

gen covid_feb_transf_abroad_higher = (covid_feb_transfers_abroad == 1) if survey_round == 3

gen covid_feb_savings_lower = (covid_feb_savings == 3) if survey_round == 3

gen covid_feb_debt_higher = (covid_feb_debt == 1) if survey_round == 3

label values covid_feb_revenue_lower covid_feb_tot_revenue_lower ///
    covid_feb_remittances_lower covid_feb_food_exp_higher covid_feb_health_exp_higher ///
    covid_feb_edu_exp_higher covid_feb_transf_abroad_higher ///
    covid_feb_savings_lower covid_feb_debt_higher ///
    yesno

********************************************************************************
*  LABOR MARKET OUTCOMES
********************************************************************************

gen last7d_working = 0
replace last7d_working = 1 if (last7d_status == 1 | eif_still_work == 1) & survey_round == 3
replace last7d_working = 1 if survey_round < 3
label values last7d_working yesno

// Employment status
gen employed = (last7d_status == 1) if survey_round == 3
replace employed = 1 if eif_still_work == 1 & survey_round == 3
label values employed yesno

// Hours worked adjustment
replace last7d_hours_worked = 0 if employed == 0 & last7d_hours_worked == .

gen		whyleft_endcontract3 = 0
replace	whyleft_endcontract3 = 1 if eif_quit_reason == 4
label values whyleft_endcontract3 yesno

********************************************************************************
*  ANALYSIS SAMPLE DEFINITION
********************************************************************************

// Set sample for analysis (exclude extreme earnings outliers)
reg inter_earnlstmonth_mid treat if survey_round == 3, robust
gen sample_r3 = 1 if survey_round == 3 & e(sample) & inter_earnlstmonth_mid < 400000
gen sample_r2 = 1 if survey_round == 2 & inter_earnlstmonth_mid < 400000
gen sample_r1 = 1 if survey_round == 1 & inter_earnlstmonth_mid < 400000

gen sample = sample_r1 if survey_round == 1
replace sample = sample_r2 if survey_round == 2
replace sample = sample_r3 if survey_round == 3

********************************************************************************
*  BASELINE VALUES FOR ANALYSIS VARIABLES
********************************************************************************

// Outcome variables
foreach var of varlist inter_earnlstmonth_mid hourly_wage inter_earnlstmonth_low inter_earnlstmonth_top {
    gen `var'_a = `var' if survey_round == 1
    bys id: egen `var'_base = max(`var'_a)
    drop `var'_a
}

// Administrative outcome variable
foreach var of varlist grade_2019_admin {
    capture gen `var'_a = `var' if survey_round == 1
    capture bys id: egen `var'_base = max(`var'_a)
    capture drop `var'_a
}

// All conscientiousness traits
foreach var of varlist trait_* {
    capture gen `var'_a = `var' if survey_round == 1
    capture bys id: egen `var'_base = max(`var'_a)
    capture drop `var'_a
    label values `var'_base easiness
}

// Big 5 personality traits
label define big5 ///
    1 "strongly disapprove" ///
    2 "somewhat disapprove" ///
    3 "neither approve nor disapprove" ///
    4 "somewhat approve" ///
    5 "strongly approve"

foreach var of varlist big5_avg_* {
    capture gen `var'_a = `var' if survey_round == 1
    capture bys id: egen `var'_base = max(`var'_a)
    capture drop `var'_a
    label values `var'_base big5
    label values `var' big5
}

// Control variables
foreach var of varlist sex age educ_high hh_n_bedrooms hh_n_children hh_n_above_18 total_debt_mid total_save_mid hhincome_mid {
    capture gen `var'_a = `var' if survey_round == 1
    capture bys id: egen `var'_base = max(`var'_a)
    capture drop `var'_a
}
label values sex_base sex
label values educ_high_base yesno

// Alternative earnings specifications baseline values
foreach var in inter_earnlstmonth_low inter_earnlstmonth_top {
    capture gen `var'_a = `var' if survey_round == 1
    capture bys id: egen `var'_base = max(`var'_a)
    capture drop `var'_a
}

********************************************************************************
*  ADDITIONAL ANALYSIS VARIABLES
********************************************************************************

// Transform earnings variables for robustness checks
gen inter_earnlstmonth_mid_ihs = asinh(inter_earnlstmonth_mid)
gen inter_earnlstmonth_mid_log = log(inter_earnlstmonth_mid)
gen inter_earnlstmonth_mid_ihs_base = asinh(inter_earnlstmonth_mid_base)
gen inter_earnlstmonth_mid_log_base = log(inter_earnlstmonth_mid_base)

// Retention and attrition indicators
by id: egen eif_still_work_end = max(eif_still_work)
la define work_end 0 "Not in company" 1 "Still in company"
la values eif_still_work_end work_end

bys id: egen appears = count(id)
gen attritor = 0
replace attritor = 1 if appears < 3
label define attrit_lab 0 "Non-attrition group" 1 "Attrition group"
label values attritor attrit_lab

* --------- Positions -------- *
gen		pos_secu = 0
replace	pos_secu = 1 if eif_pos == 1

gen		pos_maso = 0
replace	pos_maso = 1 if eif_pos == 3

gen		pos_scra = 0
replace	pos_scra = 1 if eif_pos == 4

gen		pos_form = 0
replace	pos_form = 1 if eif_pos == 5

gen		pos_carp = 0
replace	pos_carp = 1 if eif_pos == 6

gen		pos_labo = 0
replace	pos_labo = 1 if eif_pos == 7

gen		pos_driv = 0
replace	pos_driv = 1 if eif_pos == 9

gen		pos_topo = 0
replace	pos_topo = 1 if eif_pos == 10

gen		pos_flag = 0
replace	pos_flag = 1 if eif_pos == 12

gen		pos_spec = 0
replace	pos_spec = 1 if eif_pos == 13


********************************************************************************
*  VARIABLE LABELS
********************************************************************************

do "$scripts/1_data-prep/variables-labels.do"

********************************************************************************
*  ORDER
********************************************************************************

order ///
    /* Administrative variables */ ///
    id consent treat survey_round ///
    /* Demographics */ ///
    sex age yob sex_base age_base ///
    /* Education */ ///
    educ educ_high grade_2019_admin grade_2019_admin_base educ_high_base ///
    /* Residence */ ///
    resid_since resid_prev_regi recent_migr ///
    /* Sample and technical variables */ ///
    sample sample_r1 sample_r2 sample_r3 ///
    appears attritor ///
    /* Employment status and work patterns */ ///
    last7d_working employed eif_still_work eif_still_work_end bef_eif_job ///
    last7d_status last7d_days_worked last7d_hours_worked whyleft_endcontract3 eif_quit_reason ///
    currwork_sector eif_pos pos_* ///
    /* Earnings - current and changes */ ///
    earn_avg_month earn_last_month earn_avg_month_range ///
    last7d_earn_avg last7d_earn_freq ///
    last7d_oj_earn last7d_oj_earn_range ///
    earn_change_aug19 earn_dir_change_aug19 earn_amount_change_aug19 ///
    earn_change_jan20 earn_dir_change_jan20 earn_amount_change_jan20 ///
    /* Derived earnings variables */ ///
    inter_earnavgmonth_low inter_earnavgmonth_mid inter_earnavgmonth_top ///
    inter_earnlstmonth_low ///
    inter_earnlstmonth_mid ///
    inter_earnlstmonth_top ///
    month_hours_worked hourly_wage ///
    inter_earnlstmonth_mid_base hourly_wage_base ///
    inter_earnlstmonth_low_base inter_earnlstmonth_top_base ///
    inter_earnlstmonth_mid_ihs inter_earnlstmonth_mid_log ///
    inter_earnlstmonth_mid_ihs_base inter_earnlstmonth_mid_log_base ///
    /* Household characteristics */ ///
    hh_n_above_18 hh_n_children hh_n_bedrooms ///
    hh_revenue_range_r1r2 hh_revenue_range_r3 ///
    hhincome_mid ///
    hh_n_bedrooms_base hh_n_children_base hh_n_above_18_base ///
    hhincome_mid_base ///
    /* Savings and debt */ ///
    hh_formal_savings hh_informal_savings total_save_mid ///
    hh_formal_debt hh_informal_debt total_debt_mid ///
    first_formal ///
    total_debt_mid_base total_save_mid_base ///
    /* Big Five personality traits */ ///
    big5_extrovert big5_critic big5_reliable big5_anxious big5_open ///
    big5_shy big5_sympathetic big5_disorganized big5_calm big5_conventional ///
    big5_avg_extra big5_avg_agreea big5_avg_consc big5_avg_emoti big5_avg_open ///
    big5_avg_extra_base big5_avg_agreea_base big5_avg_consc_base ///
    big5_avg_emoti_base big5_avg_open_base ///
    /* Conscientiousness traits */ ///
    trait_remorse_late trait_make_plan trait_work_goals trait_tidy ///
    trait_earlier_meet trait_avoid_late trait_follow_schedule ///
    trait_followup_method trait_attentive_others trait_others_dependent ///
    trait_set_clear_goals trait_keep_promises trait_avoid_procrast ///
    trait_fulfill_promises trait_set_high_standards trait_organize_schedule ///
    trait_change_setback trait_up_to_responsib trait_on_time ///
    trait_respect_engagements trait_work_hard trait_clean_up ///
    trait_orga_pers_spaces trait_others_count ///
    trait_focus_goals trait_make_plan_for_goal trait_late_meetings ///
    trait_keep_organized trait_keep_tidy trait_fulfill_duty ///
    trait_keep_trying_if_fail trait_manage_responsib ///
    trait_remorse_late_base trait_make_plan_base trait_work_goals_base ///
    trait_tidy_base trait_earlier_meet_base trait_avoid_late_base ///
    trait_follow_schedule_base trait_followup_method_base ///
    trait_attentive_others_base trait_others_dependent_base ///
    trait_set_clear_goals_base trait_keep_promises_base ///
    trait_avoid_procrast_base trait_fulfill_promises_base ///
    trait_set_high_standards_base trait_organize_schedule_base ///
    trait_change_setback_base trait_up_to_responsib_base ///
    trait_on_time_base trait_respect_engagements_base ///
    trait_work_hard_base trait_clean_up_base ///
    trait_others_count_base ///
    trait_focus_goals_base trait_make_plan_for_goal_base ///
    trait_late_meetings_base trait_keep_organized_base ///
    trait_keep_tidy_base trait_fulfill_duty_base ///
    trait_keep_trying_if_fail_base trait_manage_responsib_base ///
    trait_orga_pers_spaces_base ///
    /* Trait averages */ ///
    trait_avg_orga trait_avg_indus trait_avg_resp trait_avg_punc ///
    trait_avg_orga_base trait_avg_indus_base trait_avg_resp_base ///
    trait_avg_punc_base ///
    /* COVID-19 protection measures */ ///
    covid_protect_m1 covid_protect_m2 covid_protect_m3 covid_protect_m4 ///
    covid_protect_m5 covid_protect_m6 covid_protect_m7 covid_protect_m8 ///
    covid_meas_count covid_effect_meas_count ///
    /* COVID-19 symptoms */ ///
    covid_sympt_cough covid_sympt_diff_breath covid_sympt_sore_throat ///
    covid_sympt_running_nose covid_sympt_muscle_pain covid_sympt_headache ///
    covid_sympt_tiredness covid_sympt_diarrhea covid_sympt_loss_smell ///
    covid_sympt_fever covid_any_sympt ///
    /* COVID-19 work changes */ ///
    covid_change_work_cond1 covid_change_work_cond2 covid_change_work_cond3 ///
    covid_change_work_cond4 covid_change_work_cond5 covid_change_work_any ///
    covid_hhm_lost_job ///
    /* COVID-19 financial impacts */ ///
    covid_feb_revenue covid_feb_tot_revenue covid_feb_remittances ///
    covid_feb_food_expenditures covid_feb_health_expenditures ///
    covid_feb_edu_expenditures covid_feb_transfers_abroad ///
    covid_feb_savings covid_feb_debt ///
    covid_feb_revenue_lower covid_feb_tot_revenue_lower ///
    covid_feb_remittances_lower covid_feb_food_exp_higher ///
    covid_feb_health_exp_higher covid_feb_edu_exp_higher ///
    covid_feb_transf_abroad_higher covid_feb_savings_lower ///
    covid_feb_debt_higher

********************************************************************************
*  SAVE ANALYSIS DATASET
********************************************************************************

notes drop _all

// Set panel structure
xtset id survey_round

save "$data/2_processed/panel_analysis.dta", replace

********************************************************************************
*  END
********************************************************************************